<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body style="height: 3000px;">
  <div id="app">
    <button @click="isShow = !isShow">{{isShow?'消失':'显示'}}</button>
    <keep-alive>
      <home v-if="isShow"></home>
    </keep-alive>
  </div>
  <script src="./vue.js"></script>
  <script>
    const Home = {
      template:`
        <div>
          <input v-model="inputTxt"/>
        </div>
      `,
      data(){
        return {
          inputTxt:''
        }
      },
      activated(){
        console.log('组件被激活了');
      },
      deactivated(){
        console.log('组件被禁用了');
      },
      beforeCreate(){
        console.log('beforeCreate');
      },
      created(){
        // 调用页面 初始化 需要 用到model函数（请求数据接口函数）
        console.log('实例创建完成-created');
        // 调用 model函数请求数据
      },
      beforeMount(){
        console.log('dom渲染完成之前');
        
      },
      mounted(){
        console.log('dom渲染完成');
      
      },
      beforeDestroy(){
        console.log('卸载之前');
      },
      destroyed(){
        console.log('组件已经卸载');
      }
    }
    Vue.component('Home', Home)
    const vm = new Vue({
      el: '#app',
      data: {
        isShow: true
      }
    })
  </script>
</body>
</html>